import requests
import re
import pyttsx3
class ttsx(object):
      def __init__(self,rate=-40):
          self.rate = rate
      def sayText(self,str):
          self.engine = pyttsx3.init()
          self.engine.setProperty('rate', 400)
          self.engine.say(str)
          self.engine.runAndWait()
ttx = ttsx()
ttx.__init__(20)
next_papge='76455797'
book=''
while 1:
    number=12
    #print(number.__str__())
    book='351509'
    #full_url = "https://www.dahuowen.com/xs/113/113120/62165"+number.__str__()+".html"#315
    full_url = "https://www.suibkk.com/read/213110/66489"+number.__str__()#460
    full_url = "https://www.suibkk.com/read/185143/63917"+number.__str__()#363
    # ull_url ="https://www.xintianxixs.com"+"/xiaoshuo/94371071/171307173.html"
    #full_url = "https://www.suibkk.com/read/253383/"+number.__str__()#9076
    #full_url = "https://www.suibkk.com/read/253383/"+next_papge#9076 69810371  yijiekaiyiguan
    #full_url = "https://www.suibkk.com/read/"+book+"/"+next_papge#9076 69810371  yijiekaiyiguan
    #full_url = "https://www.suibkk.com/read/88605/36961636"
    #https://www.suibkk.com/read/399415/80629626
    full_url = "http://www.suibkk.com/indexlist/408543/"
    #full_url = "http://www.suibkk.com"
    #full_url = "http://www.suibkk.com/fenlei/xuanhuan/1/"
    print(full_url)
    bbb = 10
    print_if= 0
    html = requests.get(full_url)
    html.encoding = 'utf-8'
    #html.encoding = 'gbk'
    pattern = re.compile(r'[^\u4e00-\u9fa5]')
    chinese = re.sub(pattern, "", html.text)
    print(html.text)
    xxxxx = html.text.replace("<br><br>", "\n")
    xxxxx = xxxxx.replace("<br /><br />", "\n")
    xxxxx = xxxxx.replace("<br/><br/>", "\n")
    xxxxx = xxxxx.replace("</p><p>", "\n")
    xxxxx = xxxxx.replace("<p>", "\n")
    xxxxx = xxxxx.replace("<br />　　<br />", "\n")
    xxxxx = xxxxx.replace("<br />", "")
    xxxxx = xxxxx.replace("“", "")
    xxxxx = xxxxx.replace("”", "")
    xxxxx = xxxxx.replace("&nbsp;&nbsp;&nbsp;&nbsp;", "\t")
    #print(xxxxx)
    # start = xxxxx.find("id=\"content\"")
    # end = xxxxx.find("nofollow")
    start = xxxxx.find("nr_nr")
    end = xxxxx.find("pb_next")
    zzzz = xxxxx[start + 25:end - 646]
    zzzz = zzzz.replace("<", "")
    zzzz = zzzz.replace("", "")
    if print_if:
        print(zzzz)
    xdf = 0
    try:
        xdf = html.text.index(">下一页")
    except:
        try:
            xdf = html.text.index(">下一章")
        except:
            print("next")
    print(html.text[xdf - 50:xdf])
    #next_papge=html.text[xdf - 50:xdf].replace("\"","").split("/read/"+book+"/")[1]
    #print(next_papge)
    if bbb:
        ttx.sayText(zzzz)


